﻿using System;
using System.Data;
using System.Web.UI;
using System.Text;
using System.Web;
using System.Web.UI.WebControls;
using System.ComponentModel;

using Lutos.User;
using Lutos.Item;
using Lutos.Data;
namespace Lutos.Control.Item
{
    public class ItemBlockControl : System.Web.UI.WebControls.WebControl
    {
        private Lutos.Item.Item[] items;  //数据源
        private int maxLength;
        private string width;
        public void Initialize(Lutos.Item.Item[] items, int maxLength, string width)
		{
		    this.items = items;
		    this.maxLength = maxLength;
		    this.width = width;
		}
        static string[] colors = new string[] { "F2F2F2", "FFFFFF" };
        protected override void Render(HtmlTextWriter output)
        {
            StringBuilder sb = new StringBuilder();
            sb.AppendFormat(
                "<table width={0} cellSpacing=0 cellPadding=0 border=0>", width);
            int i = 0;
            foreach (Lutos.Item.Item item in items)
            {
                i++;
                sb.AppendFormat("<tr><td bgcolor={3}>&nbsp;<a class=itemLink target=_blank href={0}-{1}.html title='{4}'>{2}</a></td></tr>", item.Item_ID, item.RND, ControlUtilities.StringCut(item.Item_Name, maxLength), colors[i&1], item.Item_Name);
            }
            sb.Append("</table>");
            output.Write(sb);
        }
    }
}
